package cn.com.elite;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import sfmi.component.chnchannel.chncallcenter.client.FreeInsuranceClient;
import sfmi.component.chnchannel.chncallcenter.dto.enums.ConnectMode;
import sfmi.component.chnchannel.chncallcenter.dto.freeinsurance.FIQuotation;
import sfmi.component.chnchannel.chncallcenter.dto.freeinsurance.key.FIQuotationKey;

public class confirmQuotation extends HttpServlet {
	private static final Log log=LogFactory.getLog(confirmQuotation.class);

	/**
	 * Constructor of the object.
	 */
	public confirmQuotation() {
		super();
	}

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		this.doPost(request, response);
	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String returnxml="0";
		try{
			String MainLocationCode=request.getParameter("MainLocationCode");
			log.debug("MainLocationCode:"+MainLocationCode);
			String QuotationNo=request.getParameter("QuotationNo");
			log.debug("QuotationNo:"+QuotationNo);
			String IP=Util.getIp(request);
			log.debug("IP:"+IP);
			FIQuotationKey fiQuotationKey = new FIQuotationKey();
			fiQuotationKey.setQuotationNo(QuotationNo);
			fiQuotationKey.setIpAddress(IP);
			fiQuotationKey.setMainLocationCode(MainLocationCode);
			FreeInsuranceClient freeInsuranceClient = new FreeInsuranceClient(ConnectMode.RealServer);
			FIQuotation fiQuotation = freeInsuranceClient.confirmQuotation(fiQuotationKey);
			returnxml="1";
		}catch(Exception e){
			log.error(Util.getERRO(e));
			returnxml="0";
		}
		request.setCharacterEncoding("UTF-8");
	    response.setContentType("text/html;charset=utf-8;");
	    PrintWriter out = response.getWriter();
	    log.debug("xml:"+returnxml);
	    out.print(returnxml);
	}

	/**
	 * Initialization of the servlet. <br>
	 *
	 * @throws ServletException if an error occurs
	 */
	public void init() throws ServletException {
		// Put your code here
	}

}
